/*
	MIDAS Context Based Routing
	cbr_debug.h
	Copyright (c) 2007 Radoslaw Olgierd Schoeneich
	MEAG IT PW
*/

#ifndef cbr_debug_h_
#define cbr_debug_h_

#include <fstream>

// enable/disable debugging
#ifndef CBR_DEBUG
# define CBR_DEBUG 1
#endif

/**
 * Debugging code.
 */

class cbr_Logger {
private:
	static cbr_Logger* logger;
	std::fstream logFile;

public:
	cbr_Logger(const char *filename);
	~cbr_Logger();

	void			logData(const char *str);

	static void		log(const char *fmt, ...);
};

#define cbr_log(fmt, ...) cbr_Logger::log(fmt, ## __VA_ARGS__)

extern bool debug_cbr;

#define cbr_debug(fmt, ...) \
do { \
	if (debug_cbr) \
		cbr_Logger::log(fmt, ## __VA_ARGS__); \
} while (0)

void dump_cbr_data(void *, int);

extern unsigned long log_packets;

enum {
	CBR_LOG_PACKETS_CBR_HELLO	= (1 << 0),
	CBR_LOG_PACKETS_CBR_ROUTE	= (1 << 1),
	CBR_LOG_PACKETS_CBR_DATA	= (1 << 2),
	CBR_LOG_PACKETS_IP		= (1 << 3),
	CBR_LOG_PACKETS_ETH		= (1 << 4),
	CBR_LOG_PACKETS_DISCARDED	= (1 << 5),
	CBR_LOG_ADDRESSES		= (1 << 6),
	CBR_LOG_FUNCTIONS		= (1 << 7),
	CBR_LOG_PACKETS_ALL		= CBR_LOG_PACKETS_CBR_HELLO |
					  CBR_LOG_PACKETS_CBR_ROUTE |
					  CBR_LOG_PACKETS_CBR_DATA |
					  CBR_LOG_PACKETS_IP |
					  CBR_LOG_PACKETS_ETH |
					  CBR_LOG_PACKETS_DISCARDED,
};

/**
 * Decide whether to log IP packet.
 *
 * @return 'true' if IP packet should be logged, 'false' otherwise.
 */

static inline bool cbr_log_ip_packet(void)
{
	return (log_packets & CBR_LOG_PACKETS_IP);
}

/**
 * Decide whether to log ETH packet.
 *
 * @return 'true' if ETH packet should be logged, 'false' otherwise.
 */

static inline bool cbr_log_eth_packet(void)
{
	return (log_packets & CBR_LOG_PACKETS_ETH);
}

/**
 * Decide whether to log info about discarded packet.
 *
 * @return 'true' if such info should be logged, 'false' otherwise.
 */

static inline bool cbr_log_discarded_packet(void)
{
	return (log_packets & CBR_LOG_PACKETS_DISCARDED);
}

/**
 * Decide whether to log info about IP and MAC addresses.
 *
 * @return 'true' if such info should be logged, 'false' otherwise.
 */

static inline bool cbr_log_addresses(void)
{
	return (log_packets & CBR_LOG_ADDRESSES);
}

/**
 * Decide whether to log info about function calls.
 *
 * @return 'true' if such info should be logged, 'false' otherwise.
 */

static inline bool cbr_log_functions(void)
{
	return (log_packets & CBR_LOG_FUNCTIONS);
}

#endif	// cbr_debug_h_
